#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置列数
    ui->tableWidget->setColumnCount(3);

    //tableWidget表格控件使用
    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年龄");

    //设置行数
    ui->tableWidget->setRowCount(5);


//    for(int i = 0; i < 5; i++){
//        for(int j = 0; j < 3; j++){
//            QString name("亚瑟");
//            name.append(QString::number(i));
//            name.append(QString::number(j));
//            ui->tableWidget->setItem(i, j, new QTableWidgetItem(name));
//        }
//    }

    QList<QString> nameList;
    QList<QString> sexList;
    QList<QString> ageList;

    nameList << "亚瑟" << "安其拉" << "妲己" << "赵云" << "孙悟空";
    sexList << "男" << "女" << "女" << "男" << "男";
    ageList << "12" << "22" << "33" << "44" << "55";

    //int转QString QString::number(int);

    for(int i = 0; i < 5; i++){
        int col = 0;
        ui->tableWidget->setItem(i, col++, new QTableWidgetItem(nameList[i]));
        ui->tableWidget->setItem(i, col++, new QTableWidgetItem(sexList.at(i)));
        ui->tableWidget->setItem(i, col++, new QTableWidgetItem(ageList[i]));
    }






}

Widget::~Widget()
{
    delete ui;
}
